import { FC, useEffect } from 'react'
import { Form, Input, Button ,message} from 'antd';
import { UserOutlined, LockOutlined } from '@ant-design/icons';
import './../static/css/Login.css'
import { login } from '../apis/login';
import {useNavigate} from 'react-router-dom'
const Login: FC<any> = (props: any): JSX.Element => {
    const navigate=useNavigate()
    useEffect(() => {

    }, [])
    interface uny{
        admin_name:string,
        pwd:string
    }
    const onFinish = (e:uny) => {
        loginPost(e)
    }
    const loginPost=async (user:uny)=>{

        const res:any=await login(user);
        if(res.code==="00000"){
           sessionStorage.setItem("token",res.token);
            navigate("/index");
        }
        else{
            message.error(res.msg);
        }
        console.log(res);
         
    }
    const onFinishFailed = () => {

    }
    return (
        <div className='loginbody'>
            <div className='loginform'>
                <div className="dl">登陆</div>
                <Form
                    name="basic"
                    wrapperCol={{ span: 24 }}
                    onFinish={onFinish}
                    onFinishFailed={onFinishFailed}
                    autoComplete="off"
                >
                    <Form.Item
                        className="formitem"
                        name="admin_name"
                        rules={[{ required: true, message: '账号' }]}
                    >
                        <Input prefix={<UserOutlined  className='loginico'/>} placeholder='请输入账号' size='large' />
                    </Form.Item>

                    <Form.Item
                        name="pwd"
                        rules={[{ required: true, message: '密码' }]}
                    >
                        <Input.Password prefix={<LockOutlined className='loginico' />} placeholder='请输入密码' size='large' />
                    </Form.Item>
                    <Form.Item>
                        <Button type="primary" block size='large' htmlType="submit">登陆</Button>
                    </Form.Item>
                </Form>
            </div>
        </div>
    )
}

export default Login